﻿using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace ConsoleSample.Tools.Json
{
    internal class ExcludePropertiesContractResolver : DefaultContractResolver
    {
        private readonly IEnumerable<string> _excludeProperties;

        public ExcludePropertiesContractResolver(IEnumerable<string> excludeProperties)
        {
            _excludeProperties = excludeProperties;
        }

        protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            return base.CreateProperties(type, memberSerialization).ToList()
                .FindAll(p => !_excludeProperties.Contains(p.PropertyName));
        }
    }
}
